//
//  QYScanningCodeViewController.m
//  QingYue
//
//  Created by Lei_Zhong_Xun on 2017/5/23.
//  Copyright © 2017年 com.lanou.product_A. All rights reserved.
//

#import "QYScanningCodeViewController.h"
#import "QYScanSucceedViewController.h"

@interface QYScanningCodeViewController ()

@end

@implementation QYScanningCodeViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // 注册观察者
    [SGQRCodeNotificationCenter addObserver:self selector:@selector(SGQRCodeInformationFromeAibum:) name:SGQRCodeInformationFromeAibum object:nil];
    [SGQRCodeNotificationCenter addObserver:self selector:@selector(SGQRCodeInformationFromeScanning:) name:SGQRCodeInformationFromeScanning object:nil];
    
    //发送隐藏中间大按钮的通知
    [[NSNotificationCenter defaultCenter] postNotificationName:@"buttonNotifationCenter" object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    
}

//从相册扫描过来
- (void)SGQRCodeInformationFromeAibum:(NSNotification *)noti {
    NSString *string = noti.object;
    
    if ([string hasPrefix:@"http"]) {// 扫描为二维码
        QYScanSucceedViewController *jumpVC = [[QYScanSucceedViewController alloc] init];
        jumpVC.jump_URL = string;
        [self.navigationController pushViewController:jumpVC animated:YES];
        
    } else { // 扫描结果为条形码
        
        QYScanSucceedViewController *jumpVC = [[QYScanSucceedViewController alloc] init];
        NSLog(@"!!!%@", string);
        jumpVC.jump_bar_code = string;
        [self.navigationController pushViewController:jumpVC animated:YES];
    }
}

//从摄像头扫描过来
- (void)SGQRCodeInformationFromeScanning:(NSNotification *)noti {
    SGQRCodeLog(@"noti - - %@", noti);
    NSString *string = noti.object;
    
    if ([string hasPrefix:@"http"]) {// 扫描为二维码
        QYScanSucceedViewController *jumpVC = [[QYScanSucceedViewController alloc] init];
        jumpVC.jump_URL = string;
        [self.navigationController pushViewController:jumpVC animated:YES];
        
    } else { // 扫描结果为条形码
        
        QYScanSucceedViewController *jumpVC = [[QYScanSucceedViewController alloc] init];
        jumpVC.jump_bar_code = string;
        [self.navigationController pushViewController:jumpVC animated:YES];
    }
}

- (void)dealloc {
    SGQRCodeLog(@"QRCodeScanningVC - dealloc");
    [SGQRCodeNotificationCenter removeObserver:self];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
